﻿@model Tuple<IEnumerable<CmsMedia>, IEnumerable<CmsMediaContent>>

@{
    var folders = Model.Item1;
    var mediaItems = Model.Item2;
    ResFile = "cms_Media";
 }
   
@helper FoldersTree(IEnumerable<CmsMedia> mediaFolders)
{
    if (mediaFolders != null && mediaFolders.Any())
    {
        <ul class="jqueryFileTree">
            @foreach (var folder in mediaFolders)
            {
                <li>
                    <a href="#" class="js-mediapicker-folder" data-folder-id="@folder.Id">@folder.FolderName</a>
                    @FoldersTree(folder.SubFolders)
                </li>
            }
        </ul>   
    }    
}

<div id="js-mediapicker-select-area b-form b-mediapicker">
    <div class="b-files-tree b-mediapicker__folders">
        <h3>@_("Folders")</h3>
        @if (folders != null && folders.Any())
        {
            <div class="b-mediapicker__folders-scroll">
            <ul class="jqueryFileTree">
                <li>
                    <a href="#" class="js-mediapicker-folder b-current" data-folder-id="0">@_("All")</a>
                    @FoldersTree(folders)
                </li>
            </ul>
            </div>
        }
        else
        {
            <p>@_("Empty")</p>
        }
    </div>


    <div class="b-form b-mediapicker__files">
        <h3>@_("Files")</h3>

        <div class="b-mediapicker__filefilter-w"><span>@_("Filename filter")"</span> <a id="js-mediapicker-clear-search" class="b-mediapicker__filefilter-c" href="#">@_("Clear filter")</a></div>
        <input id="js-mediapicker-searchbox" type="text" class="text valid b-mediapicker__filefilter" />
        @Html.Partial("Load", mediaItems)

        <div class="b-form b-mediapicker__buttons">
            <button id="js-mediapicker-close-btn" class="b-button b-button_small b-button_colour_grey">@_("Cancel")</button>
            <button id="js-mediapicker-ok-btn" class="b-button b-button_small" data-element-id="@ViewBag.ElementId" data-content-id="0" data-content-title="">@_("Choose selected file")</button>
        </div>

    </div>
</div>

